package com.snail.ron.design.factory;

import com.snail.ron.design.factory.abstractFactory.facory.AbstractFactory;
import com.snail.ron.design.factory.abstractFactory.facory.impl.DellAbstractFactory;
import com.snail.ron.design.factory.abstractFactory.facory.impl.HPAbstractFactory;
import com.snail.ron.design.factory.abstractFactory.model.MainFrame;
import com.snail.ron.design.factory.abstractFactory.model.Monitor;
import com.snail.ron.design.factory.factory.Factory;
import com.snail.ron.design.factory.factory.impl.DellFactory;
import com.snail.ron.design.factory.model.Keyboard;
import com.snail.ron.design.factory.simple.SimpleFactory;

/**
 * @author xueguoping
 * @desc: TODO
 * @date 2022/4/1410:14
 */
public class Client {
    public static void main(String[] args) {
        //simpleFactory
        //simpleFactory(1);

        //factory
        /*try {
            factory(DellFactory.class.getName());
        }catch (ClassNotFoundException classNotFoundException){

        }catch (InstantiationException instantiationException){

        }catch (IllegalAccessException illegalAccessException){

        }*/


        //abstract factory
        try {
            abstractFactory(DellAbstractFactory.class.getName());
        }catch (ClassNotFoundException classNotFoundException){

        }catch (InstantiationException instantiationException){

        }catch (IllegalAccessException illegalAccessException){

        }
    }

    public static void simpleFactory(int brand){
        SimpleFactory factory = new SimpleFactory();
        Keyboard instance = factory.getInstance(brand);
        instance.input();
        instance.print();
    }

    public static void factory(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        Class<?> aClass = Class.forName(className);
        Factory factory= (Factory) aClass.newInstance();
        Keyboard keyboard = factory.getInstance();
        keyboard.input();
        keyboard.print();
    }

    public static void abstractFactory(String className)throws ClassNotFoundException, InstantiationException, IllegalAccessException{
        Class<?> aClass = Class.forName(className);
        AbstractFactory abstractFactory = (AbstractFactory) aClass.newInstance();
        com.snail.ron.design.factory.abstractFactory.model.Keyboard keyboard = abstractFactory.createKeyboard();
        keyboard.print();
        MainFrame mainFrame = abstractFactory.createMainFrame();
        mainFrame.run();
        Monitor monitor = abstractFactory.createMonitor();
        monitor.play();
        //AbstractFactory abstractFactory =
    }
}
